<#import "/spring.ftl" as spring />
<#import "html-macro.ftl" as h />
<div class="dashedbar text-blue"><span>集装箱信息</span></div>
<#--只读模式不显示-->
<div class="ui inline form">
<#if !h.readMode__>
    <div class="ui grid" id="declaContainers">
        <div class="row">
            <input id="id" type="hidden"/>
            <@h.label width="6" value="集装箱号"/>
            <@h.input width="10" id="containerNo" />
            <@h.label width="6" value="集装箱规格" />
            <@h.dropdown width="10" id="containerStandard" showId="sizeShow" />
            <@h.label width="6" value="自重(KG)" />
            <@h.input width="10" id="containerWeight" dataType="float" />
        </div>
    </div>
    <div class="ui error message"></div>
    <div class="row ui grid button-line">
        <div class="fifteen wide column right floated">
            <button id="containersAdd" class="mini ui labeled icon button blue right floated">
                <i class="plus icon"></i>
                添加
            </button>
            <button id="containersSave" class="mini ui labeled icon button blue right floated "
                    style="display: none;">
                <i class="save icon"></i>
                保存
            </button>
            <button id="containersCancle" class="mini ui labeled icon button blue right floated "
                    style="display: none;">
                <i class="remove icon"></i>
                取消
            </button>
            <button id="fetchBtn" class="mini ui labeled icon button blue right floated"
                    style="display: none;">
                <i class="fa-cloud-download icon"></i>
                获取柜号
            </button>
            <button class="mini ui labeled icon button blue right floated"
                    id="importContainerListButton">
                <i class="small add circle icon"></i>
                柜号excel导入
            </button>
            <a class="ui"
               href="<@spring.url "/order/download/excel_container"/>">下载柜模板 </a>
            <input type="file" id="fileForBox" accept=".xls" style="display:none;"/>
        </div>
    </div>
</#if>
    <table name="containerTable" class="ui celled table center aligned notAutoIncrease"
           style="font-size: 12px;">
        <thead>
        <th>集装箱号</th>
        <th>集装箱规格</th>
        <th>自重</th>
        <#--只读模式不显示-->
        <#if !h.readMode__>
        <th>操作</th>
        </#if>
        </thead>
        <tbody>
        <#list declaration.declaContainers as dc>
        <tr>
            <input name="declaContainers[${dc_index}].id" type="hidden" value="${dc.id}">
            <input name="declaContainers[${dc_index}].containerNo" type="hidden"
                   value="${dc.containerNo}">
        <#--<input name="declaContainers[${dc_index}].sizeShow" type="hidden" value="">-->
            <input name="declaContainers[${dc_index}].containerStandard" type="hidden"
                   value="${dc.containerStandard}">
            <input name="declaContainers[${dc_index}].containerWeight" type="hidden"
                   value="${dc.containerWeight}">
            <td>${dc.containerNo}</td>
            <td>${dc.containerStandard}</td>
            <td>${dc.containerWeight}</td>
            <#if !h.readMode__>
                <td>
                    <button class="ui mini primary basic button">修改</button>
                    <button class="ui mini negative basic button">删除</button>
                </td>
            </#if>
        </tr>
        </#list>
        </tbody>
    </table>
</div>
<div class="dashedbar text-blue"><span>随附单证信息</span></div>
<div class="ui inline form">
<#--只读模式不显示-->
<#if !h.readMode__>
    <div class="ui grid" id="suiFuDans">
        <div class="row">
            <input id="id" type="hidden"/>
            <@h.label width="6" value="单证代码" />
            <@h.dropdown width="10" id="suifudan_co" showId="suifudan_co_cn" />
            <@h.label width="6" value="单证编号" />
            <@h.input width="10" id="suifudan_no" />
        </div>
    </div>
    <div class="ui error message"></div>
    <div class="row ui grid button-line">
        <div class="fifteen wide column right floated">
            <button id="attachedAdd" class="mini ui labeled icon button blue right floated">
                <i class="plus icon"></i>
                添加
            </button>
            <button id="attachedSave" class="mini ui labeled icon button blue right floated">
                <i class="plus icon"></i>
                保存
            </button>
            <button id="attachedCancle" class="mini ui labeled icon button blue right floated">
                <i class="remove icon"></i>
                取消
            </button>
        </div>
    </div>
</#if>
    <table name="suifudanTable" class="ui celled table center aligned notAutoIncrease"
           style="font-size: 12px;">
        <thead>
        <th>单证代码</th>
        <th>单证编号</th>
        <#--只读模式不显示-->
        <#if !h.readMode__>
        <th>操作</th>
        </#if>
        </thead>
        <tbody>
        <#list declaration.suiFuDans as sfd>
        <tr>
            <input name="suiFuDans[${sfd_index}].id" type="hidden" value="${sfd.id}">
            <input name="suiFuDans[${sfd_index}].suifudan_co" type="hidden"
                   value="${sfd.suifudan_co}">
            <input name="suiFuDans[${sfd_index}].suifudan_co_cn" type="hidden"
                   value="${sfd.suifudan_co_cn}">
            <input name="suiFuDans[${sfd_index}].suifudan_no" type="hidden"
                   value="${sfd.suifudan_no}">
            <td>${sfd.suifudan_co}</td>
            <td>${sfd.suifudan_no}</td>
        <#--只读模式不显示-->
            <#if !h.readMode__>
                <td>
                    <button class="ui mini primary basic button">修改</button>
                    <button class="ui mini negative basic button">删除</button>
                </td>
            </#if>
        </tr>
        </#list>
        </tbody>
    </table>
</div>

<div class="ui inline form otherForm">
    <div class="ui grid">
        <div class="row">
            <div class="dashedbar text-blue"><span style="font-size: 12px">其他事项确认</span>
            </div>
        <@h.label width="6" value="特殊关系确认" required=true />
        <@h.dropdown width="10" name="special_relationship_confirm"  value="${((declaration.special_relationship_confirm)?length>0)?string(declaration.special_relationship_confirm,'1')}"/>
        <#--<@h.dropdown width="10" name="special_relationship_confirm"  value="${declaration.special_relationship_confirm}"/>-->
        <@h.label width="6" value="价格影响确认" required=true />
        <@h.dropdown width="10" name="price_impact_confirm"  value="${((declaration.price_impact_confirm)?length>0)?string(declaration.price_impact_confirm,'1')}"/>
        <#--<@h.dropdown width="10" name="price_impact_confirm"  value="${declaration.price_impact_confirm}"/>-->
        <@h.label width="6" value="支付特许权使用费确认" required=true />
        <@h.dropdown width="10" name="payment_royaltils_confirm"  value="${((declaration.payment_royaltils_confirm)?length>0)?string(declaration.payment_royaltils_confirm,'1')}"/>
        <#--<@h.dropdown width="10" name="payment_royaltils_confirm"  value="${declaration.payment_royaltils_confirm}"/>-->
            <div class="dashedbar text-blue"></div>
        <@h.label width="6" value="关联报关单号"  />
        <@h.input width="10" name="re_manifest" value="${declaration.re_manifest}"/>
        <@h.label width="6" value="关联备案号" />
        <@h.input width="10" name="re_record_id"  value="${declaration.re_record_id}"/>
        <@h.label width="6" value="保税/监管场所" />
        <@h.input width="10" name="re_jianguan"  value="${declaration.re_jianguan}"/>
        <@h.label width="6" value="货场代码" />
        <@h.dropdown width="10" name="re_yard_id"  value="${declaration.re_yard_id}"/>
        <@h.label width="6" value="转关提前报关" />
        <@h.dropdown width="10" name="declarUp"  value="${declaration.declarUp}"/>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        $(".ui.radio.checkbox").checkbox();
        //获取柜号
        $("#fetchBtn").click(function () {
            layer.open({
                           title: "获取柜号",
                           area: '350px',
                           content: "<div class=\"ui one column grid\" id=\"fetchContainerDiv\"><div class=\"row\"><div class=\"column\" style='color: #9F3A38;'></div><div class=\"column ui input\"><input id=\"fetchContainerNo\" type=\"text\" placeholder=\"请输入任意一个柜号获取...\" style=\" width: 100%;\"></div></div></div>",
                           success: function () {
                               var $input = $("#fetchContainerNo");
                               $input.focus();
                               $input.blur(function () {
                                   var v = $input.val();
                                   if (v) {
                                       $input.val(v.toLocaleUpperCase());
                                   }
                               });
                           },
                           yes: function (index) {
                               var $input = $("#fetchContainerNo");
                               var containerNo = $input.val();
                               if (containerNo) {
                                   var $errorMsgDom = $input.parent().prev();
                                   if (!/^[A-Z]{4}\d{7}$/.test(containerNo)) {
                                       $errorMsgDom.text("柜号格式不正确，格式：四个字母+7个数字");
                                       $input.parent().addClass("error");
                                   } else {
                                       $errorMsgDom.text("");
                                       $("#fetchContainerDiv").addClass("ui segment loading");
                                       $.ajax({
                                                  url: "<@spring.url "/business/declaration-getContainerInfoVal"/>",
                                                  data: {
                                                      "container_no": containerNo,
                                                      "work_type": "0"
                                                  },
                                                  success: function (data, textStatus, jqXHR) {
                                                      var containers = eval(data.containerInfo);
                                                      if (containers.length == 0) {
                                                          layer.alert("没有获取到柜号，请确认柜号是否正确!");
                                                      } else {
                                                          var bid = containers[0].WORK_NO
                                                                  ? containers[0].WORK_NO.split(
                                                                  ",")[0] : "";
                                                          var regDate = containers[0].REG_DATE
                                                                  ? containers[0].REG_DATE.split(
                                                                  ",")[0] : "";
                                                          var type = containers[0].IO_TYPE
                                                                  ? containers[0].IO_TYPE.split(
                                                                  ",")[0] : "";
                                                          if (bid) {
                                                              layer.alert(
                                                                      "请注意，当前柜号已存在三联单资料<br/>相关流水号为："
                                                                      + bid + "<br/>日期：" + regDate
                                                                      + "<br/>类型：" + (type == "I"
                                                                              ? "进口"
                                                                              : "出口"));
                                                          }
                                                          $.each(containers, function (i, n) {
                                                              var $containersAdd = $(
                                                                      "#containersAdd");
                                                              if (!$containersAdd.is(":hidden")) {
                                                                  $containersAdd.click();
                                                              }
                                                              $("#containerNo").val(n.CONTAINER_NO);
                                                              var $ctSizeDropdown = $(
                                                                      "#containerStandard").parent();
                                                              var ctSize = n.CT_SIZE == "20" ? "S"
                                                                      : "L";
                                                              $ctSizeDropdown.dropdown(
                                                                      "set selected",
                                                                      ctSize);
                                                              $("#containersSave").click();
                                                          })
                                                      }
                                                  },
                                                  error: function (XMLHttpRequest, textStatus,
                                                                   errorThrown) {
                                                      layer.error("获取柜号出错!");
                                                  },
                                                  complete: function () {
                                                      $("#fetchContainerDiv").remove(
                                                              "ui segment loading");
                                                  }
                                              });
                                   }
                               } else {
                                   $input.parent().addClass("error");
                                   $input.focus();
                               }
                           }
                       });
        });
    });
</script>